package com.yjhb.android.sbz.v2.mvp.presenter

import com.yjhb.android.sbz.entity.UserInfo
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.v2.mvp.V2ConventionPresenter
import com.yjhb.android.sbz.v2.mvp.view.BindTelView


/**
 *  创建者 zx
 *  创建时间 2021/8/6 9:04
 */
class LoginBindTelPresenter(v: BindTelView) : V2ConventionPresenter<BindTelView>(v) {


    fun sendPhoneVerifyCode(tel: String) {
        view?.onWait()
        model?.let {
            HttpTool.request(it.sendPhoneVerifyCode(tel), object : HttpObserver<Any?>() {
                override fun onResult(data: Any?) {
                    view?.onCodeSendSuccess()
                }

                override fun onError(code: Int, msg: String?) {
                    view?.onFailure(code, msg)
                }
            })
        }
    }

    fun bindPhoneAndSyncData(openid: String, phone: String, code: String) {
        view?.onWait()
        model?.let {
            HttpTool.request(it.bindPhoneAndSyncData(openid, phone, code), object : HttpObserver<Boolean?>() {
                override fun onResult(data: Boolean?) {
                    view?.onBindSuccess()
                }

                override fun onError(code: Int, msg: String?) {
                    view?.onFailure(code, msg)
                }
            })
        }
    }

    fun newWxLogin(openId:String,device:String){
        view?.onWait()
        model?.let {
            HttpTool.request(it.wxLoginNew(openId,device),object : HttpObserver<UserInfo?>() {
                override fun onResult(data: UserInfo?) {
                    data?.let {
                        d ->
                        view?.onLoginSuccess(d)
                    }
                }

                override fun onError(code: Int, msg: String?) {
                    view?.onFailure(code, msg)
                }
            })

        }
    }

}